package erfgame.core.util;

import java.awt.Point;
import java.util.List;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;


import erfgame.core.dao.ObjectDAO;
import erfgame.core.world.World;
import erfgame.core.world.WorldDAOManager;
import erfgame.core.world.terrain.BlockGridTiles;
import erfgame.core.world.terrain.GridTile;

public class WorldLinkTester {
	@Test
	public void checkLinks() {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/beans/beans.xml");
		WorldDAOManager daoManager = (WorldDAOManager)context.getBean("worldDAOManager");
		List<World> worlds = daoManager.getWorldDAO().getWorlds();
		for( World world : worlds ) {
			checkLinks( world, daoManager );
		}
	}
	
	public void checkLinks( World world, WorldDAOManager daoManager ) {
		ObjectDAO<Point, BlockGridTiles> gridTilesDAO = daoManager.getGridTilesDAO(world);
		for( int bx=0; bx<world.getBlocksX(); bx++ ) {
			for( int by=0; by<world.getBlocksY(); by++ ) {
				System.out.println( "["+bx+","+by+"]");
				Point b = new Point( bx, by );
				BlockGridTiles tiles = gridTilesDAO.retrieveObject(b);
				for( int gx=0; gx<world.getXGridTilesPerBlock(); gx++ ) {
					for( int gy=0; gy<world.getYGridTilesPerBlock(); gy++ ) {
						GridTile[] gridTiles = tiles.getGridTiles(gx, gy);
						System.out.println( "("+gx+","+gy+")" );
						for( int i=0; i<gridTiles.length; i++ ) {
							GridTile gridTile = gridTiles[i];

						}
					}
				}
			}
		}
		
	}
}
